if ( typeof query !== 'undefined' && query ) { //do stuff if query is defined and not null } else { }